package com.cictec.middleware.ribbon.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.cictec.middleware.core.pojo.MiddlewarePosition;

/**
 * 
 * 
 * @author ql
 */
@Component
@Aspect
public class TermilalUploadInfoAspect {

	public static Logger logger = LoggerFactory.getLogger(TermilalUploadInfoAspect.class);

	/**
	 * 获取原始点位置信息数组，读取第一个和最后一个点的信息
	 * 
	 * @param pjp
	 * @throws Throwable
	 */
	@Before("execution(* com.cictec.middleware.distribute.controller.MiddlewarePositionController.positionUpload(..))")
	public void saveFirstAndLastPoint(JoinPoint pjp) throws Throwable {
		MiddlewarePosition position = (MiddlewarePosition) pjp.getArgs()[0];

		ThreadContextHolder.setValue(position.getDevCode(), position.getCityCode());
	}

	/**
	 * 更新里程统计信息
	 * 
	 * @param pjp
	 * @throws Throwable
	 */
	@Before("execution(* com.cictec.middleware.distribute.controller.MiddlewarePositionController.enterOutUpload(..))")
	public void updateStation(JoinPoint pjp) throws Throwable {
		MiddlewarePosition position = (MiddlewarePosition) pjp.getArgs()[0];
		ThreadContextHolder.setValue(position.getDevCode(), position.getCityCode());
	}
	
	

}
